package com.webiatech.server.uploadfile;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;

public class ByteExtractor {

	public static ByteArrayOutputStream extractBytes(HttpServletRequest request)
	{
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		try {
			
			InputStream input = request.getInputStream();
	
			int bytesRead = 0;
			while(bytesRead != -1){
				byte[] buffer = new byte[1024];	
				bytesRead = input.read(buffer,0,1024);
				if(bytesRead > 0){
					bos.write(buffer, 0, bytesRead);
				}
			}
	
			input.close();
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
		
		return bos;
	}
}
